package com.lmk.ms.common.vo.obs;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 对象存储的文件信息
 *
 * @author laomake@hotmail.com
 * @version 1.0
 * @date 2022/7/6
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "对象存储的文件信息")
public class OssFileVO {

    @Schema(description = "原始文件名")
    private String name;

    @Schema(description = "文件扩展名")
    private String type;

    @Schema(description = "文件大小")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long length;

    @Schema(description = "友好方式显示的文件大小")
    private String size;

    @Schema(description = "文件地址")
    private String url;

    public OssFileVO(String name, String url) {
        this.name = name;
        this.type = name.substring(name.lastIndexOf("."));
        this.url = url;
    }

    public OssFileVO(String name, String type, String url) {
        this.name = name;
        this.type = type;
        this.url = url;
    }

    public OssFileVO(String name, String url, Long length, String size) {
        this.name = name;
        this.type = name.substring(name.lastIndexOf("."));
        this.url = url;
        this.length = length;
        this.size = size;
    }
}